package com.lyz.dataStructure.xiancheng.多线程;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/7/11 14:50
 *@Description:
 **/
public class CallableThreadTest implements Callable<Integer> {


    @Override
    public Integer call() throws Exception {
       int i =0;
        for(;i<20;i++){
            System.out.println(Thread.currentThread().getName()+" "+i);
        }
        return i;
    }


    public static void main(String[] args) {
        CallableThreadTest ctt =new CallableThreadTest();
        FutureTask<Integer> ft = new FutureTask<>(ctt);
        for(int i =0;i<10;i++){
            System.out.println(Thread.currentThread().getName()+" "+i);
            if(i==5){
                new Thread(ft,"线程1").start();
            }
        }
        try {
            System.out.println("子线程的返回值："+ft.get());
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
